/*
package com.example.demo.time.ip;

import cn.hutool.core.util.StrUtil;
import org.lionsoul.ip2region.DataBlock;
import org.lionsoul.ip2region.DbConfig;
import org.lionsoul.ip2region.DbSearcher;
import sun.misc.IOUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.logging.Logger;

import static sun.awt.AppContext.log;

public class GetRealIpUtil {
    private static String getIpInfo(String ip) {
        ip="192.168.200.61";
        String ipInfo = null;
        try {
            DbConfig config = new DbConfig();
            InputStream inputStream = GetRealIpUtil.class.getClassLoader().getResourceAsStream("ip2region/ip2region.db");
            byte[] mybyte = IOUtils.readAllBytes(inputStream);
            DbSearcher searcher = new DbSearcher(config, mybyte);
            DataBlock dataBlock = searcher.memorySearch(ip);
            ipInfo = dataBlock.toString();
            if (StrUtil.isNotBlank(ipInfo)) {
                ipInfo = new String(ipInfo.getBytes("gbk"), StandardCharsets.UTF_8);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ipInfo;
    }
    */
/**
     * 根据ip 获取用户的地区
     *
     * @param request
     * @date 2019/5/14 15:31
     *//*

    public static String getUserAreaIdFromRequest(HttpServletRequest request) {
        Logger log = null;
        String areaName = null;
        String ipInfo = GetRealIpUtil.getIpInfo("192.168.200.61");
        if (StrUtil.isNotBlank(ipInfo)) {
            // 1:内网ip (0|0|0|0|内网IP|内网IP|16392)
            // 0|0|0|0|内网IP|内网IP|16392
            // 0|中国|0|北京|北京市|移动|183155
            // 0|中国|0|海南省|0|电信|153149
            // 0|中国|0|海南省|海口市|电信|153094
            String[] ipInfoArr = StrUtil.split(ipInfo, "|").toArray(new String[0]);
            if (ipInfoArr != null && ipInfoArr.length == 7) {
                String countryName = ipInfoArr[1];
                String provinceName = ipInfoArr[3];
                String cityName = ipInfoArr[4];
                if ("0".equals(countryName) && "内网IP".equals(provinceName) && "内网IP".equals(cityName)) {
                    areaName = "中国";
                } else {
                    if ("中国".equals(countryName)) {
                        //省份不为空
                        if (StrUtil.isNotBlank(provinceName)) {
                            // 去掉“省”字
                            if (provinceName.contains("省")) {
                                provinceName = provinceName.substring(0, provinceName.length() - 1);
                            }
                        } else {
                            if (StrUtil.isNotBlank(cityName)) {
                                // 去掉“市”字
                                cityName = cityName.substring(0, cityName.length() - 1);
                                Areas.Area area = Areas.instance.getAreaByName(cityName);
                            } else {
                                areaName = "中国";
                            }
                        }

                    }
                }

                log.info("从ip中获取的地区名称---> 国家：{}, 省份：{}, 城市：{}", countryName, provinceName, cityName);
            }
        }
        return areaName;
    }
}
*/
